package com.agile.leetcode.hutool.bloomfilter;

import cn.hutool.bloomfilter.BitMapBloomFilter;
import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;

import java.nio.charset.Charset;

/**
 * hutool布隆过滤器的使用
 *
 * @Author:ChenZhangKun
 * @Date: 2021/9/23 17:03
 */
public class BloomFilterDemo {
    public static void main(String[] args) {
        // 布隆过滤器的使用
        BitMapBloomFilter filter = new BitMapBloomFilter(10);
        // 添加元素
        filter.add("czk");
        filter.add("czj");
        filter.add("czh");
        filter.add("czr");
        System.out.println(filter.contains("czr"));


        BloomFilter<CharSequence> bloomFilter = BloomFilter.create(Funnels.stringFunnel(Charset.forName("utf-8")), 100, 0.0001);
        bloomFilter.put("c");
        bloomFilter.put("d");
        boolean d = bloomFilter.mightContain("d");
        System.out.println(d);
    }
}
